package day4;

public class Point1 {
    // 横坐标和纵坐标使用整型
    public int x;
    public int y;

    // 无参构造器，默认创建点(0,0)
    public Point1() {
        this.x = 0;
        this.y = 0;
    }

    // 有参构造器，创建指定坐标的点
    public Point1(int x, int y) {
        this.x = x;
        this.y = y;
    }

    // 计算到另一点的距离
    public double distance(Point other) {
        int dx = this.x - other.x;
        int dy = this.y - other.y;
        return Math.sqrt(dx * dx + dy * dy);
    }

    // 计算到指定坐标点的距离
    public double distance(int x, int y) {
        int dx = this.x - x;
        int dy = this.y - y;
        return Math.sqrt(dx * dx + dy * dy);
    }

    // 计算到原点的距离
    public double distance() {
        return Math.sqrt(this.x * this.x + this.y * this.y);
    }
}
